import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutterstudyapplast/common/utils.dart';
import 'package:flutterstudyapplast/ui/page/page_webvew.dart';

class ArticleItem extends StatefulWidget {
  final itemData;

  ArticleItem(this.itemData);

  @override
  _ArticleItemState createState() => _ArticleItemState();
}

class _ArticleItemState extends State<ArticleItem> {
  @override
  Widget build(BuildContext context) {
    ///时间和作者
    Row author = Row(
      children: <Widget>[
        Expanded(
          child: Text.rich(TextSpan(
            children: [
              TextSpan(text: "作者"),
              TextSpan(
                text: widget.itemData.author??"没有作者",
                style: TextStyle(color: Theme.of(context).primaryColor)
              )
            ]
          )),
        ),
        Text(widget.itemData.niceDate??"没有日期")
      ],
    );
    ///标题
    Text title = Text(widget.itemData.title??"没有标题",style: TextStyle(color: Colors.black,fontSize: 16),textAlign: TextAlign.left);
    ///章节
    Text chapter = Text(widget.itemData.chapterName??"没有章节",style: TextStyle(color: Theme.of(context).primaryColor));
    Column column = Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Padding(
          padding: EdgeInsets.all(10),
          child:author
        ),
        Padding(
          padding: EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
          child: title
        ),
        Padding(
          padding: EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
          child: chapter
        )
      ],
    );
    return Card(
      elevation: 4,
      child: InkWell(
        child: column,
        onTap: ()async{
          ///todo 点击去往webview
         // Utils.openUrl(widget.itemData['title'], widget.itemData["link"]);
          Navigator.push(context, MaterialPageRoute(builder: (_){
            return WebViewPage(
              widget.itemData,
              isCanCollect: true,
            );
          }));
        },
      ),
    );
  }
}
